import bluetooth
import time
import psutil
import time


target_address = "48:E7:29:C0:02:96"

sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((target_address, 1))
print(psutil.net_io_counters(pernic=True))
while True:
    s1 = psutil.net_io_counters(pernic=True)['wlp4s0']
    time.sleep(1)
    s2 = psutil.net_io_counters(pernic=True)['wlp4s0']
    print('s1:', s1)
    print('s2:', s2)
    result = s2.bytes_recv - s1.bytes_recv
    print(str('%d' % (result / 1024)) + 'kb/s')
    sock.send(bytes(str('%d' % (result / 1024)) + 'kb/s', 'utf-8'))
    # time.sleep(1)
sock.close()
